package com.johnny.springai.mcpstdioserver.service;

import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;

@Service
public class OpenMeteoService {
    //Metet免费天气API基础URL
    static final String BASE_URL = "https://api.open-meteo.com/v1";

    final RestClient restClient;

    @Autowired
    public OpenMeteoService(RestClient.Builder restClientBuilder) {
        this.restClient = restClientBuilder.build();
    }

    @Tool(description = "根据提供的经纬度获取当地的天气，根据位置自动获取经纬度")
    public String getWeather(double latitude, double longitude) {
        String url = BASE_URL + "/forecast?latitude=" + latitude + "&longitude=" + longitude + "&hourly=temperature_2m,relativehumidity_2m,windspeed_10m";
        return restClient.get().uri(url).retrieve().body(String.class);
    }

}
